package com.turing.manage.computer;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.Map;


import com.turing.dao.Dao;
import com.turing.dao.DaoImpl;

public class ComputerService {
	
	Dao dao = new DaoImpl();
	
	public List<Map<String, Object>> queryClasssAll() throws ClassNotFoundException, SQLException {
		return dao.executeQueryForList("select * from computer");
	}

	public void addClasss(String computer_pinpai, String computer_time) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException {
		String sql="insert into computer values('"+(int)(Math.random()*100)+"',?,?)";
		
		int [] types=new int [2];
		types[0]=Types.VARCHAR;
		types[1]=Types.VARCHAR;
		
		Object [] values=new Object[2];
		values[0]=computer_time;
		values [1] =computer_pinpai;
		dao.executeUpdate(sql, types, values);

	}

	public Map<String, Object> editForMap(String id) throws ClassNotFoundException, SQLException {
		return dao.executeQueryForMap("select * from computer where computer_id='"+id+"'");
	}

	public void editClasss(String computer_id, String computer_pinpai, String computer_time) throws ClassNotFoundException, SQLException {
		dao.executeUpdate("update computer set computer_pinpai='"+computer_pinpai+"',computer_time='"+computer_time+"' where computer_id='"+computer_id+"'");
	}

	/**
	 * @desc  实现级联删除+批量删除
	 * @param ids
	 * @throws IOException 
	 * @throws SQLException 
	 * @throws FileNotFoundException 
	 * @throws ClassNotFoundException 
	 */


	

	public void deleteClasss(String[] ids) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException {
		 for(int i =0;i<ids.length;i++)
	     {
	    	 	String sql_5="DELETE FROM  computer WHERE  computer_id=?";
	    	 	dao.executeUpdate(sql_5, new int []{Types.VARCHAR}, new Object[]{ids[i]});
	     }
		
	}


}
